<?php
echo $this->Html->script('pagination/pagination');
?>
<script type="text/javascript">
    var pagination_options = {
      num_edge_entries: 2,
      num_display_entries: 8,
      callback: pageselectCallback,
      items_per_page:6
    }
    function pageselectCallback(page_index, jq){
      var items_per_page = pagination_options.items_per_page;
      var offset = page_index * items_per_page;
      var new_content = $('#hidden-table-content ul.block').slice(offset, offset + items_per_page).clone();
      //new_content = $('#customer').html()+new_content;
      $('#table-content').empty().append($('#customer').html()).append(new_content);
      return false;
    }
    function initPagination() {
      var num_entries = $('ul.block').length;
      // Create pagination element
      $("#pagination").pagination(num_entries, pagination_options);
    }
    $(document).ready(function(){      
      initPagination();
    });
</script>
<div id="content">
    <div id="page-heading">
        <h1>Response for survey <?=$survey['Survey']['title']?>
          <?php echo $this->Html->link("Export", array('controller' => "responses", 'action' => 'export', $survey['Survey']['id'], 'admin' => true),array('class'=>'button')); ?>
          <?php echo $this->Html->link("See summary of responses", array('controller' => "responses", 'action' => 'summary',$survey['Survey']['id'], 'admin' => true),array('class'=>'button')); ?>
          <?php echo $this->Html->link("Back to Survey", array('controller' => "surveys", 'action' => 'index', 'admin' => true),array('class'=>'button')); ?>
        </h1>
    </div>
    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
        <tr>
            <th rowspan="3" class="sized">
                <?php echo $this->Html->image('../images/shared/side_shadowleft.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
            </th>
            <th class="topleft"></th>
            <td id="tbl-border-top">&nbsp;</td>
            <th class="topright"></th>
            <th rowspan="3" class="sized">
                <?php echo $this->Html->image('../images/shared/side_shadowright.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
            </th>
	</tr>
	<tr>
            <td id="tbl-border-left"></td>
            <td>
                <div id="content-table-inner">
                    <div id="pagination" class="pagination">
                        
                    </div>
                    <br style="clear:both;" />
                    <div id="table-content"></div>
                    <?php if($survey['Survey']['type']==Survey::EXAMINATION){ ?>
                        <div id="customer" style="display: none">
                            <?php 
                            $i=0;
                            $return[0][0]='<span class="right">Right Answer</span><br/><span class="wrong">Wrong Answer</span>';
                            foreach($return as $value){ 
                                if($i==0){
                                ?>
                            <ul class="block">
                                <?php foreach ($value as $val) { ?>
                                <li class="options">
                                    <?php if(is_array($val)){ 
                                        if(count($val)>1){
                                        ?>
                                        <?php foreach ($val as $v) {?>
                                            <span class="<?php echo ($v['check']==1)?"right":"wrong" ?>" ><?=$v['title']?></span><br/>          
                                        <?php } ?>
                                    <?php }else{ ?>
                                    <?php foreach ($val as $v) {?>
                                        <span class="<?php echo ($v['check']==1)?"right":"wrong" ?>" ><?=$v['title']?></span>          
                                    <?php } ?>
                                    <?php }}else{?>
                                        <?=$val?>
                                    <?php } ?>
                                </li>
                               <?php  } ?>
                            </ul>
                            <?php 
                            } 
                            $i++;} ?>
                        </div>
                        <div id="hidden-table-content" style="display: none">
                            <?php 
                            $i=0;
                            foreach($return as $value){ 
                                if($i>0){
                                ?>
                            <ul class="block">
                                <?php foreach ($value as $val) { ?>
                                <li class="options">
                                    <?php if(is_array($val)){ 
                                        if(count($val)>1){
                                        ?>
                                        <?php foreach ($val as $v) {?>
                                            <span class="<?php echo ($v['check']==1)?"right":"wrong" ?>" ><?=$v['title']?></span><br/>          
                                        <?php } ?>
                                    <?php }else{ ?>
                                    <?php foreach ($val as $v) {?>
                                        <span class="<?php echo ($v['check']==1)?"right":"wrong" ?>" ><?=$v['title']?></span>          
                                    <?php } ?>
                                    <?php }}else{?>
                                        <?=$val?>
                                    <?php } ?>
                                </li>
                               <?php  } ?>
                            </ul>
                            <?php 
                            } 
                            $i++;} ?>
                            <div class="clear"></div>
                        </div>
                    <?php }else{ ?>
                    <div id="customer" style="display: none">
                        <?php 
                        $i=0;
                        foreach($return as $value){ 
                            if($i==0){
                            ?>
                        <ul class="block">
                            <?php foreach ($value as $val) { ?>
                            <li class="options">
                                <?php if(is_array($val)){ 
                                    if(count($val)>1){
                                    ?>
                                    <?php foreach ($val as $v) {?>
                                    <?=$v?><br/>          
                                    <?php } ?>
                                <?php }else{
                                    echo implode(",", $val);
                                }}else{?>
                                    <?=$val?>
                                <?php } ?>
                            </li>
                           <?php  } ?>
                        </ul>
                        <?php 
                        } 
                        $i++;} ?>
                    </div>
                    <div id="hidden-table-content" style="display: none">
                        <?php 
                        $i=0;
                        foreach($return as $value){ 
                            if($i>0){
                            ?>
                        <ul class="block">
                            <?php foreach ($value as $val) { ?>
                            <li class="options">
                                <?php if(is_array($val)){ 
                                    if(count($val)>1){
                                    ?>
                                    <?php foreach ($val as $v) {?>
                                    <?=$v?><br/>          
                                    <?php } ?>
                                <?php }else{
                                    echo implode(",", $val);
                                }}else{?>
                                    <?=$val?>
                                <?php } ?>
                            </li>
                           <?php  } ?>
                        </ul>
                        <?php 
                        } 
                        $i++;} ?>
                        
                        <div class="clear"></div>
                    </div>
                    <?php } ?>
                </div>
            </td>
            <td id="tbl-border-right"></td>
	</tr>
	<tr>
            <th class="sized bottomleft"></th>
            <td id="tbl-border-bottom">&nbsp;</td>
            <th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
<script type="text/javascript">
jQuery(document).ready(function(){
            jQuery("#surveyMenu").addClass('current');
});
</script>